﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Helper;
using System.Data.Objects;

namespace DLL
{
    public class SettingRepo
    {
        public Setting Get()
        {
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                return dbContext.Settings.FirstOrDefault();
            }
        }

        public void Update(Setting setting)
        {
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                dbContext.Entry(setting).State = System.Data.EntityState.Modified;
                dbContext.SaveChanges();
            }
        }

        public bool ChangeProtectPass(string newPass, out string hashPass)
        {
            bool result = false;
            hashPass = Encrypt.Hash(newPass);
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                Setting setting = Get();
                setting.SecurityPassword = hashPass;
                Update(setting);
                result = true;
            }
            return result;
        }

        public bool Reset()
        {
            bool result = false;
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                ObjectParameter vbitSuccess = new ObjectParameter("vbitSuccess", typeof(bool));
                dbContext.pResetSell(vbitSuccess);
                result = Convert.ToBoolean(vbitSuccess.Value);
            }
            return result;
        }

        public void ResetProductAmount()
        {
            using (RetailManagementEntities dbContext = new RetailManagementEntities())
            {
                dbContext.pResetProductAmount();
            }
        }
    }
}
